package com.skplanet.rade.domain;

import java.io.Serializable;
import java.util.Comparator;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.google.gson.annotations.Expose;

@Entity
@Table(name = "usertag")
public class UserTag implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public UserTag() {
		this.count = 0;
		this.score = 0;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Expose
	private Long utid;

	@Column(name = "keyword")
	@Expose
	private String keyword;

	@Column(name = "count")
	@Expose
	private int count;

	@Column(name = "score")
	@Expose
	private double score;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "user_uid")
	private User user;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "tag_tid")
	private Tag tag;

	public Long getUtid() {
		return utid;
	}

	public void setUtid(Long utid) {
		this.utid = utid;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public void addCount() {
		this.count = this.getCount() + 1;
	}

	public double getScore() {
		return score;
	}

	public void setScore(double score) {
		this.score = score;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Tag getTag() {
		return tag;
	}

	public void setTag(Tag tag) {
		this.tag = tag;
	}

	// UserTag 대소 비교 함수
	private static final Comparator<UserTag> userTagComparator = new Comparator<UserTag>() {

		@Override
		public int compare(UserTag object1, UserTag object2) {
			return (object1.getCount() - object2.getCount());
		}
	};

	public static Comparator<UserTag> getUsertagcomparator() {
		return userTagComparator;
	}
}
